library(cjoint)

dta <- read.csv("mturk_dta.csv")

##############
## Figure 3 ##
##############

# Set baseline categories
baselines <- list()
baselines$occup_profile <- "Business Owner"
baselines$shared_party <- "No Party"
baselines$incumb_profile <- "No"
baselines$gender_profile <- "Male"
baselines$race_profile <- "White"

# Analysis
fig3 <- amce(vote ~ occup_profile + shared_party + incumb_profile +
               race_profile + gender_profile, data = dta, cluster = TRUE,
             respondent.id = "mturk_ids_rep", baselines = baselines)

# Plotting the results

fig3_out <- plot(fig3, xlab = "Change in Pr(Vote)", label.baseline = TRUE, colors = "black",
                 text.size = 10, attribute.names = c("Gender", "Incumbency Status",
                                                     "Occupation",
                                                     "Race", "Shared Party"))

###############
## Figure A1 ##
###############

# Set baseline categories
baselines <- list()
baselines$occup_profile <- "Business Owner"
baselines$`Candidate-Respondent Party` <- "No Party"
baselines$incumb_profile <- "No"
baselines$gender_profile <- "Male"
baselines$race_profile <- "White"

# Analysis
figa1 <- amce(vote ~ occup_profile*`Candidate-Respondent Party` + party_profile + incumb_profile +
              race_profile + gender_profile, data = dta, cluster = TRUE,
            respondent.id = "mturk_ids_rep", baselines = baselines, respondent.varying = "`Candidate-Respondent Party`")

# Plotting the results
figa1_out <- plot(figa1, xlab = "Change in Pr(Vote)", 
                facet.names = "`Candidate-Respondent Party`", respondent.varying = "`Candidate-Respondent Party`", 
                plot.display = "interaction", label.baseline = TRUE, colors = "black",
                attribute.names = c("Gender", "Incumbency Status",
                                    "Occupation", "Party",
                                    "Race"), text.size = 10)